from sklearn.datasets import load_digits
from sklearn.manifold import TSNE
import matplotlib.pyplot as plt
import seaborn as sns

# 数据集
digits = load_digits()
X = digits.data
y = digits.target

# t-SNE分析
tsne = TSNE(n_components=2, perplexity=30, verbose=2)
X_tsne = tsne.fit_transform(X)

# 绘制结果
plt.figure(figsize=(10, 10))
sns.scatterplot(x=X_tsne[:, 0], y=X_tsne[:, 1], hue=y, legend='full', palette='Spectral')
plt.title('t-SNE')
plt.show()
